home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / dev / lang / pcq12src.lzh / Runtime / Readers / readarb.asm < prev    next >
Assembly Source File  |  1990-12-10  |  2KB  |  75 lines

  1.  
  2. *    ReadArb.asm (of PCQ Pascal runtime library)
  3. *    Copyright (c) 1989 Patrick Quaid
  4.  
  5. *    This routine copies memory from the file buffer into the
  6. *    variable's memory space.
  7. *
  8. *    Upon entry, this routine expects a0 to hold the address of
  9. *    the variable.  The top of the stack should be the address
  10. *    of the file record.
  11.  
  12. *    Alogrithm for ReadArb:
  13. *
  14. *    if IOResult <> 0 then
  15. *        return
  16. *    if EOF then
  17. *        set IOResult
  18. *        return
  19. *    if Interactive then
  20. *        if Current >= Last then
  21. *        FillBuffer
  22. *        if EOF then
  23. *            set IOResult
  24. *            return
  25. *    copy RecSize bytes from Current to VarAddress
  26. *    CURRENT := CURRENT + RECSIZE
  27. *    if not INTERACTIVE then
  28. *        if CURRENT >= LAST then
  29. *        FillBuffer
  30. *
  31.  
  32.     INCLUDE    "/FileRec.i"
  33.  
  34.     SECTION    PCQ_Runtime,CODE
  35.  
  36.     XREF    _p%FillBuffer
  37.     XREF    _p%IOResult
  38.  
  39.     XDEF    _p%ReadArb
  40. _p%ReadArb
  41.  
  42.     tst.l    _p%IOResult        ; is IO OK?
  43.     bne    4$            ; if not, skip everything
  44.     move.l    4(sp),a1        ; get file record
  45.     tst.b    EOF(a1)            ; are we at EOF?
  46.     beq.s    1$            ; if not, skip
  47.     rts
  48. 1$    tst.b    INTERACTIVE(a1)        ; is it interactive?
  49.     beq.s    2$            ; if not, skip this bit
  50.     move.l    CURRENT(a1),d0        ; get current address
  51.     cmp.l    LAST(a1),d0        ; are we empty?
  52.     blt.s    2$            ; if not, skip
  53.     move.l    a0,-(sp)        ; save var address
  54.     move.l    a1,a0            ; set up for the call
  55.     jsr    _p%FillBuffer        ; fill the buffer
  56.     move.l    (sp)+,a0        ; restore the address
  57.     move.l    4(sp),a1        ; get file record back
  58.     tst.b    EOF(a1)            ; are we at EOF?
  59.     beq.s    2$            ; if not, go on
  60.     rts                ; return since EOF
  61. 2$    move.l    RECSIZE(a1),d0        ; number of bytes to copy
  62.     subq.l    #1,d0
  63.     move.l    CURRENT(a1),a1        ; get current address
  64. 3$    move.b    (a1)+,d1        ; get byte
  65.     move.b    d1,(a0)+        ; copy byte
  66.     dbra    d0,3$            ; loop
  67.     move.l    4(sp),a0        ; get file record
  68.     move.l    a1,CURRENT(a0)        ; set current to proper value
  69.     cmp.l    LAST(a0),a1        ; end of buffer ?
  70.     blt.s    4$            ; if not, skip
  71.     jsr    _p%FillBuffer        ; otherwise fill the buffer
  72. 4$    rts
  73.  
  74.     END
  75.